<?php

namespace app\api\controller\carbon\knowledge;

use app\common\controller\Api;
use think\Db;

/**
 * 核算类型接口
 */
class Type extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 获取类别
     *
     */
    public function index()
    {
        $type_id = $this->request->request('type_id');
        if ($type_id) {
            $list = model('app\admin\model\carbon\knowledge\Type')
                ->where('superior_id', $type_id)
                ->where('level', 2)
                ->select();
        } else {
            $list = model('app\admin\model\carbon\knowledge\Type')
                ->where('level', 1)
                ->select();
            foreach ($list as $key => $value) {
                $value->juniorlist = model('app\admin\model\carbon\knowledge\Type')
                    ->where('superior_id', $value['id'])
                    ->where('level', 2)
                    ->select();
            }
        }

        $this->success('获取成功', $list);
    }
}
